using System;
using System.Collections.Generic;
using System.Text;
using My.IdlConverter.Core.Config;

namespace My.IdlConverter.Sdkmachine
{
    public class AssemblyLine : IAssemblyLine
    {
        IWorkshop workshop = new StandardWorkshop();

        public AssemblyLine()
        {
        }

        public virtual IWorkshop Workshop
        {
            set
            {
                workshop = value;
            }
        }

        public event ProductEventHandler Running;
        public virtual void Produce(string targetPath)
        {
            if (workshop == null)
                return;

            NotifyRunning("Start", RunState.Start);

            EnvironmentConfig publicConfig = new EnvironmentConfig();
            string fartartPath = publicConfig.IdlConverterpath;
            Config.SdkmachineConfig sdkConfig = new Config.SdkmachineConfig();

            NotifyRunning("include folder",RunState.Running);
            workshop.ProductPubicInclude(sdkConfig.PublicFilePaths, fartartPath,targetPath);
            workshop.ProductDomInclude(sdkConfig.DomPath, fartartPath, targetPath);

            NotifyRunning("lib folder", RunState.Running);
            workshop.ProductLib(sdkConfig.LibPaths,fartartPath,targetPath);

            NotifyRunning("bin folder", RunState.Running);
            workshop.ProductBin(targetPath);

            NotifyRunning("obj folder", RunState.Running);
            workshop.ProductObj(targetPath);

            NotifyRunning("src folder", RunState.Running);
            workshop.ProductSrc(targetPath);

            //NotifyRunning("documents folder", RunState.Running);
            //workshop.ProductDocs(null,targetPath);

            NotifyRunning("tools folder", RunState.Running);
            workshop.ProductTools(null,targetPath);

            NotifyRunning("samples folder", RunState.Running);
            workshop.ProductSamples(null,targetPath);

            NotifyRunning("end", RunState.End);
        }

        private void NotifyRunning(string kind, RunState state)
        {
            if (Running != null)
            {
                Running(workshop, kind, state);
            }
        }
    }
}
